package com.tleng.Nodos;

import org.antlr.runtime.Token;
import org.antlr.runtime.tree.CommonTree;


public class NodoParentesis extends NodoGenerico {

	public NodoParentesis(Token t) 
	{
		super(t);
	}
	
    public NodoParentesis(CommonTree node)
    { 
    	super(node); 
    }
    
    private NodoGenerico E1() { return this; }
    private NodoGenerico E2() { return (NodoGenerico)this.getChild(0); }
    
    public String Imprimir()
    {
    	return ImprimirParentesisAbre() + E2().Imprimir() + ImprimirParentesisCierra();
    }
    
    private String ImprimirParentesisAbre()
    {
    	return "gsave " + this.x + " " + (this.y - this.alto_inferior) + " moveto " + ancho_parentesis + " " + (this.altoTotal() + this.alto_inferior) + " scale (\\() show grestore\n";
    }

    private String ImprimirParentesisCierra()
    {
    	return "gsave " + (this.x+this.ancho-ancho_parentesis/2) + " " + (this.y - this.alto_inferior) + " moveto " + ancho_parentesis + " " + (this.altoTotal() + this.alto_inferior) + " scale (\\)) show grestore\n";
    }
    
    /**
     Caso E1 = (E2) ( parentesis )
	-----------------------------
	
	E2().x = E1().x + ancho_parentesis
	E2().y = E1().y
	E2().escala = E1().escala
	
	E1().ancho = E2().ancho + 2*ancho_parentesis
	E1().alto_superior = E2().alto_superior
	E1().alto_inferior = E2().alto_inferior
     */
    
    public void calcularX()
    {
    	E2().x = E1().x + ancho_parentesis/2;
    	E2().calcularX();
    }
    
    public void calcularY()
    {
    	E2().y = E1().y;
    	
    	E2().calcularY();
    }
    
    public void calcularEscala()
    {
    	E2().escala = E1().escala;
    	
    	E2().calcularEscala();
    }
    
    public void calcularAncho()
    {
    	E2().calcularAncho();
    	E1().ancho = E2().ancho + ancho_parentesis;
    }
    
    public void calcularAlto()
    {
    	E2().calcularAlto();
    	E1().alto_superior = E2().alto_superior;
    	E1().alto_inferior = E2().alto_inferior;
    }
}
